package com.jingdianjichi.subject.application.controller;

import com.jingdianjichi.subject.infra.basic.service.SubjectEsService2;
import com.jingdianjichi.subject.infra.entity.UserInfo;
import com.jingdianjichi.subject.infra.rpc.UserRpc;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 董代恒
 * @version 1.0
 */
@RestController
@RequestMapping("/subject/category")
@Slf4j
public class TestFeignController {

    @Resource
    private SubjectEsService2 subjectEsService2;

    @Resource
    private UserRpc userRpc;

    @GetMapping("/testFeign")
    public void testFeign() {
        UserInfo userInfo = userRpc.getUserInfo("oAxu-6E5mC77wLcDV6YxJRc4kdYg");
        log.info("TestFeignController.testFeign.userInfo={}", userInfo);
    }

    /**
     * 创建索引
     */
    @GetMapping("/testCreateIndex")
    public String testCreateIndex() {
        subjectEsService2.createIndex();
        return "成功";
    }

    /**
     * 添加文档
     *
     * @return
     */
    @PostMapping("/addDocs")
    public String addDocs() {
        subjectEsService2.addDoc();
        return "成功";
    }

    @GetMapping("/find")
    public String find() {
        subjectEsService2.find();
        return "成功";
    }

    @GetMapping("/search")
    public String search() {
        subjectEsService2.search();
        return "成功";
    }
}
